//app.js
App({
  onLaunch: function (opt) {
    const updateManager = wx.getUpdateManager()

    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
      console.log(res.hasUpdate)
    })

    updateManager.onUpdateReady(function () {
      wx.showModal({
        title: '更新提示',
        content: '新版本已经准备好，是否重启应用？',
        success: function (res) {
          if (res.confirm) {
            // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate()
          }
        }
      })
    })

    updateManager.onUpdateFailed(function () {
      // 新的版本下载失败
      wx.showToast({
        title: '新版本下载失败，请检查网络',
        icon:'none'
      })
    })
    const utils = require("utils/util.js");
    const glob = this.globalData;
    let nickname = wx.getStorageSync('user_msg').nickname,
      pic = wx.getStorageSync('user_msg').avatar,
      time = wx.getStorageSync('user_msg').timeout,
      nowtime = new Date().getTime(),
      uid = wx.getStorageSync('user_info').uid;
    if (utils.empty(nickname) && utils.empty(pic) && nowtime - Number(time) <= 60000) {

    } else {
      utils.ajax(glob.ROOT_URL + 'members/' + uid, {
        header: {
          "Accept": 'application/vnd.dct.v1+json'
        }
      }, res => {
        if (res.state == "1") {
          let time = new Date().getTime();
          let data = res.data;
          data.timeout = time;
          wx.setStorageSync('user_msg', data);
        }
      })
    }
  },
  onShow: function (opt) {
    
  },
  globalData: {
      userInfo: null,
      ROOT_URL: 'https://duozs.duocaitou.com/api/',
      rooturl: 'https://dctapi.duocaitou.com/v1/',
      NIMappkey: '10068a57fa5b859d373b6211321f00b7'
  },
  //登录状态
  loginState: function () {
    let user_Info = wx.getStorageSync('user_info');
    if (user_Info.uid == "" || user_Info.uid == undefined || user_Info.uid == null) {
      wx.redirectTo({
        url: '/pages/views/login/login',
      })
      return false;
    }
    let nowtime = new Date().getTime(), oldtime = Number(user_Info.timeout);
    if (nowtime - oldtime >= 604800000) {
      wx.removeStorageSync('user_info');
      wx.redirectTo({
        url: '/pages/views/login/login',
      })
      return false;
    }
    return true;
  }
})
// {
//     "pagePath": "pages/shareholders/shareholders",
//         "text": "股东群",
//             "iconPath": "resource/img/tabbar/gdq_default.png",
//                 "selectedIconPath": "resource/img/tabbar/gdq_selected.png"
// },